<!--
 *                   ___====-_  _-====___
 *             _--^^^#####//      \\#####^^^--_
 *          _-^##########// (    ) \\##########^-_
 *         -############//  |\^^/|  \\############-
 *       _/############//   (@::@)   \############\_
 *      /#############((     \\//     ))#############\
 *     -###############\\    (oo)    //###############-
 *    -#################\\  / VV \  //#################-
 *   -###################\\/      \//###################-
 *  _#/|##########/\######(   /\   )######/\##########|\#_
 *  |/ |#/\#/\#/\/  \#/\##\  |  |  /##/\#/  \/\#/\#/\#| \|
 *  `  |/  V  V  `   V  \#\| |  | |/#/  V   '  V  V  \|  '
 *     `   `  `      `   / | |  | | \   '      '  '   '
 *                      (  | |  | |  )
 *                     __\ | |  | | /__
 *                    (vvv(VVV)(VVV)vvv)
 * 
 *      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *                神兽保佑            永无BUG
 * 通用附件下载
 -->





<template>
  <div>
    <span @click="download">
      <slot>
        <a-button class="hte-btn" style="margin-right: 10px;margin-bottom: 10px;">下载模板</a-button>
      </slot>
    </span>

    <hte-upload
      v-if="reload"
      v-show="false"
      :accept="accept"
      dbKey="Trd"
      ftpKey="ftp"
      :zipFileName="zipFileName"
      :queryParams="queryParams"
      :showPage="false"
      v-model="fileList"
      :onSuccess="onSuccess"
      :onChange="onChange"
      class="uploader-example"
      ref="uploader"
      @file-error="fileError"
      @file-complete="fileComplete"
      @complete="complete"
    ></hte-upload>
  </div>
</template>

<script>
import '@/config/hteupload.install.js'

export default {
  name: 'commonAttachDownload',
  components: {},
  props: {
    busKey: { type: String },
    downloadType: {
      type: Number,
      default: 0,
      require: false,
    },
    zipFileName: {
      type: String,
      default: '模板文件',
    },
  },
  data() {
    return {
      reload: true,
      queryParams: {
        dbKey: 'Trd',
        busField: 'attachTemplate',
        ftpKey: 'ftp',
        busKey: this.busKey,
      },

      accept: '*',
      fileList: [],
      attachTypes: [],
    }
  },
  watch: {
    busKey: function (newValue, oldValue) {
      if (newValue != oldValue) {
        this.reload = false
        this.$nextTick((res) => {
          this.reload = true
        })
      }
    },
  },
  mounted() {
  },
  methods: {
    download() {
      this.$refs.uploader.download(1)
    },

    setFileList() {
      this.fileList = []
    },

    onSuccess(res, file, fileList) {},
    onChange(file, fileList) {},
    fileError(res, file, fileList) {},
    complete() {},
    fileComplete(rootFile, file, response, chunk) {},
  },
}
</script>

<style lang="less" scoped>
</style>
